﻿using System;
using System.ComponentModel;

namespace Alimentador.Foods
{
    /// <summary>
    /// Enumerator for Food Property Names
    /// </summary>
    public enum PropertyName
    {
        [Description("Ficha")]
        Ficha = 1,

        [Description("Percentagem")]
        Percentagem = 3,
        [Description("Energia")]
        Energia = 5,
        [Description("Água")]
        Agua = 7,
        [Description("Proteína")]
        Proteina,
        [Description("Lípidos")]
        GorduraTotal,
        [Description("Hidratos Carbono")]
        TotalHidratosCarbono,
        [Description("Total H. C. em Monossacáridos")]
        TotalHidratosCarbonoMono,
        [Description("Mono-Dissacáridos")]
        MonoDissacaridos,
        [Description("Ácidos Orgânicos")]
        AcidosOrganicos,
        [Description("Álcool")]
        Alcool,
        [Description("Amido")]
        Amido,
        [Description("Oligassacáridos")]
        Oligassacaridos,
        [Description("Fibra Alimentar")]
        FibraAlimentar,

        [Description("Ácidos Gordos Saturados")]
        AcidosGordosSaturados = 19,
        [Description("Ácidos Gordos Monoinsaturados")]
        AcidosGordosMonoinsaturados,
        [Description("Ácidos Gordos Polinsaturados")]
        AcidosGordosPolinsaturados,
        [Description("Ácidos Gordos Trans")]
        AcidosGordosTrans,
        [Description("Ácidos Linoleicos")]
        AcidosLinoleico,

        [Description("Colesterol")]
        Colesterol = 25,

        [Description("Vitamina-A Total")]
        VitaminaATotal = 27,
        [Description("Caroteno")]
        Caroteno,
        [Description("Vitamina-D")]
        VitaminaD,
        [Description("A-tocoferol")]
        ATocoferol,
        [Description("Tiamina")]
        Tiamina,
        [Description("Riboflavina")]
        Riboflavina,
        [Description("Equivalentes de Niacina")]
        EquivalentesDeNiacina,
        [Description("Niacina")]
        Niacina,
        [Description("Triptofano 60")]
        Triptofano60,
        [Description("Vitamina B6")]
        VitaminaB6,
        [Description("Vitamina B12")]
        VitaminaB12,
        [Description("Vitamina C")]
        VitaminaC,
        [Description("Folatos")]
        Folatos,

        [Description("Cinza")]
        Cinza = 41,
        [Description("Sódio")]
        Sodio,
        [Description("Potássio")]
        Potassio,
        [Description("Cálcio")]
        Calcio,
        [Description("Fósforo")]
        Fosforo,
        [Description("Magnésio")]
        Magnesio,
        [Description("Ferro")]
        Ferro,
        [Description("Zinco")]
        Zinco,

        [Description("Porção")]
        Porcao = 50,

        [Description("Recomendado")]
        Recomended
    }

    /// <summary>
    /// Constructor
    /// </summary>
    public class FoodProperty
    {
        /// <summary>
        /// Return the PropertyName value
        /// </summary>
        public PropertyName PropertyName { get; set; }
        /// <summary>
        /// String value for units
        /// </summary>
        public string Unit { get; set; }
        /// <summary>
        /// Double value for quantity
        /// </summary>
        private double m_quantity = 0;
        public double Quantity
        {
            get
            {
                return Math.Round(m_quantity, 2);
            }
            set
            {
                m_quantity = value;
            }
        }

        /// <summary>
        /// Return the string value of property
        /// </summary>
        public string GetPropertyName
        {
            get
            {
                return MainHelper.GetEnumDescription(PropertyName);
            }
        }

        public string GetNameAndPercentage
        {
            get
            {
                return GetPropertyName + ": " + Quantity.ToString("F2") + "%";
            }
        }

        /// <summary>
        /// Default constructor
        /// </summary>
        public FoodProperty() { }

        /// <summary>
        /// Constructor with parameters
        /// </summary>
        /// <param name="propName">PropertyName</param>
        /// <param name="quant">double</param>
        public FoodProperty(PropertyName propName, double quant)
        {
            this.PropertyName = propName;
            this.Unit = SetUnitByPropertyName(propName);
            this.Quantity = quant;
        }

        /// <summary>
        /// Return the unit according to given property
        /// </summary>
        /// <param name="propName">PropertyName</param>
        /// <returns>string</returns>
        public static string SetUnitByPropertyName(PropertyName propName)
        {
            switch (propName)
            {
                case PropertyName.Energia:
                    {
                        return "Kcal";
                    }
                case PropertyName.Agua:
                case PropertyName.Proteina:
                case PropertyName.GorduraTotal:
                case PropertyName.TotalHidratosCarbono:
                case PropertyName.TotalHidratosCarbonoMono:
                case PropertyName.MonoDissacaridos:
                case PropertyName.AcidosOrganicos:
                case PropertyName.Alcool:
                case PropertyName.Oligassacaridos:
                case PropertyName.FibraAlimentar:
                case PropertyName.AcidosGordosSaturados:
                case PropertyName.AcidosGordosMonoinsaturados:
                case PropertyName.AcidosGordosPolinsaturados:
                case PropertyName.AcidosGordosTrans:
                case PropertyName.AcidosLinoleico:
                case PropertyName.Porcao:
                    {
                        return "g";
                    }
                case PropertyName.VitaminaATotal:
                case PropertyName.VitaminaD:
                case PropertyName.VitaminaB12:
                case PropertyName.Folatos:
                    {
                        return "ug";
                    }
                case PropertyName.Colesterol:
                case PropertyName.Caroteno:
                case PropertyName.ATocoferol:
                case PropertyName.Tiamina:
                case PropertyName.Riboflavina:
                case PropertyName.EquivalentesDeNiacina:
                case PropertyName.Niacina:
                case PropertyName.Triptofano60:
                case PropertyName.VitaminaB6:
                case PropertyName.VitaminaC:
                case PropertyName.Sodio:
                case PropertyName.Potassio:
                case PropertyName.Calcio:
                case PropertyName.Fosforo:
                case PropertyName.Magnesio:
                case PropertyName.Ferro:
                case PropertyName.Zinco:
                    {
                        return "mg";
                    }
                case PropertyName.Cinza:
                default:
                    {
                        return "g";
                    }
            }
        }
    }
}
